<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>

        const str = 'dsadasdad';
        //定义规则 查找字符串中是否有
        const reg = /adas/;
        //匹配 规则.test(被检查的字符串); return 返回true/false
        console.log(reg.test(str));
        //检索符合规则的字符串 规则.exec(被检查的字符串); return 返回数组/null
        console.log(reg.exec(str));
        //-------------
        // 元字符
        //1.边界符 ^开头 $结尾
        const reg1 = /^哈/;
        console.log(/^哈/.test('哈'));
        console.log(/^的哈/.test('哈'));
        console.log(/哈$/.test('哈'));
        console.log(/哈$/.test('哈是'));
        // 精确匹配 表哈开头哈结尾 一个1字符 其余情况为false
        console.log(/^哈$/.test('哈'));
        console.log('----------------------------------------------');

        //2.量词 某个模式出现的次数
        //* >=0次
        //+ >=1次
        //? 0/1次
        //{n} n次
        //{n,} >=n
        //{n,m} >=n && <=m
        console.log(/^哈*$/.test('哈哈'));//true
        console.log(/^哈*$/.test(''));//true
        console.log(/^哈*$/.test('哈k哈'));//false
        console.log('----------------------------------------------');
        console.log(/^哈+$/.test(''));//false
        console.log(/^哈+$/.test('哈'));//true
        console.log('----------------------------------------------');
        console.log(/^哈?$/.test('哈'));//true
        console.log(/^哈?$/.test(''));//true
        console.log(/^哈?$/.test('哈哈'));//false
        console.log('----------------------------------------------');
        console.log(/^哈{1}$/.test('哈'));//true
        console.log(/^哈{3}$/.test('哈哈哈'));//true
        console.log(/^哈{1,6}$/.test('哈哈哈哈哈哈'));//true
        console.log(/^哈{1,6}$/.test('哈哈哈哈哈哈哈哈'));//false



    </script>
</body>

</html>